package com.to8to.autotask.scheduler;

import it.sauronsoftware.cron4j.SchedulerListener;
import it.sauronsoftware.cron4j.Task;
import it.sauronsoftware.cron4j.TaskExecutor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * AutoTaskSchedulerListener.java
 * 作 者：atom.liu
 * 版 本：v2.0
 * 日 期：2014年12月1日
 * 描 述：自动任务调度的监听类
 */
public class AutoTaskSchedulerListener implements SchedulerListener
{
    private static final Logger logger = LoggerFactory.getLogger(AutoTaskSchedulerListener.class);

    @Override
    public void taskFailed(TaskExecutor taskexecutor, Throwable throwable)
    {
        Task task = taskexecutor.getTask();
        logger.error(String.format("自动任务[ %s ]执行失败！", task.toString()), throwable);
    }

    @Override
    public void taskLaunching(TaskExecutor taskexecutor)
    {
        Task task = taskexecutor.getTask();
        logger.info(String.format("自动任务[ %s ]开始执行！", task.toString()));
    }

    @Override
    public void taskSucceeded(TaskExecutor taskexecutor)
    {
        Task task = taskexecutor.getTask();
        logger.info(String.format("自动任务[ %s ]执行成功！", task.toString()));
    }
}
